﻿var db=gw.db('wenwen.sqlite').open();
function wgu(){
	var qid=document.getElementById('qId').value;
	var answer=db.getData("select question,answer from ww where qid="+qid,[0,0])[0][1];
	for(var i=0;i<4;i++){
		if(answer==document.querySelectorAll('#qAnswers span')[i].textContent.substr(2)){
			setTimeout(function(){
				QzApp.answerQ(qid,i);
			},1500);
			return;
		}
	}
};

var QzApp = (function(){
    var API_URL = ["0?", "0?", "0?", "1?", "1?", "1?", "2?", "2?", "2?", "2?", "3?", "3?", "3?", "3?", "3?"];
    var PRISE_BLOG_URL = "/z/QzoneCoursePrise.htm";
    var PRISE_PIC_URL = "/z/QzonePrisePic";
    var keyParam = "";
    var challengeType = "";
    var vcourseCategoryId = "";
    var prisePicPath = "";
    var userId = "";
    var userName = "";
    var timer = null;
    var time = 0;
    var buttonLock = true;
    var pageY = 0;
    var topListSize = 20;
    var todayScore = -1;
    var maxScoure = -1;
    var currentpoints_test = 0;
    var currentpoints_notest = 0;
    var uins = new Array();
    try {
        pageY = parent.QZFL.dom.getXY(parent.QZFL.dom.getById("appModule"))[1]
    } 
    catch (e) {
    }
    var OPR_GET_TOP20_LIST = 1;
    var OPR_START_CHALLENGE = 2;
    var OPR_ANSWER_QUESTION = 3;
    var OPR_END_CHALLENGE = 4;
    var OPR_DAY_SIGN = 5;
    var OPR_GET_TOP_LIST = 7;
    var TIME_LIMIT_CHALLENGE = 180;
    var TIME_LIMIT_TEST = 200;
    var TOKEN = "";
    var _t = 0;
    var ajax_time_opr = [];
    var DEFAULT_BACK_URL = "qzone/arena_theme1.jpg";
    var CourseCategoryData = [{
        id: 1,
        title: "\u4e0a\u4e0b\u4e94\u5343\u5e74",
        cid: "EliteLemmaPage.e?sp=1",
        bgPic: "i/Qzonecourse_his.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 2,
        title: "\u793e\u4f1a\u4eba\u6587",
        cid: "EliteLemmaPage.e?sp=4",
        bgPic: "i/Qzonecourse_renwen.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 3,
        title: "\u5999\u8da3\u751f\u6d3b",
        cid: "EliteLemmaPage.e?sp=9",
        bgPic: "i/Qzonecourse_life.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 4,
        title: "\u6211\u7231\u5065\u5eb7",
        cid: "EliteLemmaPage.e?sp=2",
        bgPic: "i/Qzonecourse_hel.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 5,
        title: "\u4f53\u575b\u98ce\u4e91",
        cid: "EliteLemmaPage.htm",
        bgPic: "i/Qzonecourse_sport.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 6,
        title: "\u661f\u5ea7\u8fd0\u52bf",
        cid: "EliteLemmaPage.e?sp=3",
        bgPic: "i/Qzonecourse_xingzuo.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 7,
        title: "\u5927\u5343\u4e16\u754c",
        cid: "EliteLemmaPage.e?sp=6",
        bgPic: "i/Qzonecourse_daqianshijie.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 8,
        title: "\u5a31\u4e50\u65e0\u6781\u9650",
        cid: "EliteLemmaPage.e?sp=7",
        bgPic: "i/Qzonecourse_yule.jpg",
        type: 1,
        desc: "",
        isHot: false
    }, {
        id: 12,
        title: "\u5c0f\u767d\u5927\u4f5c\u6218",
        cid: "http://xb.qq.com/",
        bgPic: "i/Qzonecourse_xb.jpg",
        type: 3,
        desc: "",
        isHot: false
    }, {
        id: 10,
        title: "qzone\u4efb\u52a1",
        cid: "",
        bgPic: "i/Qzone.jpg",
        type: 0,
        desc: "",
        isHot: false
    }];
    var QidToWenwenQuestion = {
        "638": "2006244823",
        "639": "2005941498",
        "640": "2004362561",
        "641": "2004861880",
        "642": "2006066990",
        "643": "2006066878",
        "644": "2006066486",
        "645": "2006066466",
        "646": "2006244833",
        "647": "2004296394",
        "648": "2006066457",
        "649": "2006068582",
        "650": "2005941617",
        "651": "2006131293",
        "652": "2006134947",
        "653": "2004851711",
        "654": "2005941546",
        "655": "2004973115",
        "656": "2006066083",
        "657": "2006066905",
        "658": "2006038347",
        "659": "2006038347",
        "660": "2004362561",
        "661": "2006016597",
        "662": "2004362561",
        "663": "2004362561",
        "664": "2006168777",
        "665": "2006244833",
        "726": "2002609176",
        "727": "181859206",
        "728": "2003723721",
        "729": "181019578",
        "730": "2002692048",
        "731": "2003723993",
        "732": "143554981",
        "733": "127505691",
        "734": "43966565",
        "735": "2006293119",
        "736": "179476177",
        "737": "176177193",
        "738": "175592900",
        "739": "2006048519",
        "740": "2006048519",
        "741": "2004313548",
        "742": "2005989923",
        "743": "2005946259",
        "744": "2006244823",
        "745": "2006168777",
        "746": "2004530603",
        "747": "2006297638",
        "748": "2006226583"
    };
    function initCourseCategory(){
        if (CourseCategoryData) {
            var ul = get("course_category");
            for (var i = 0; i < CourseCategoryData.length; i++) {
                if (CourseCategoryData[i].type > 0) {
                    var li = document.createElement("li");
                    var span1 = newElement("span", {
                        "class": "subject"
                    });
                    span1.innerHTML = CourseCategoryData[i].title;
                    var span2 = newElement("span");
                    var testA = newElement("a", {
                        "class": "test"
                    });
                    testA.href = "QzoneCourse.e?sp=" + CourseCategoryData[i].id + "&sp=1#";
                    testA.innerHTML = "\u968f\u5802\u5c0f\u8003";
                    span2.appendChild(testA);
                    if (document.location.href.indexOf("?from=") > 0) {
                        testA.onclick = function(){
                            _sendStat("from", "enter")
                        };
                        testA.name = "ncmc"
                    }
                    var challengeA = null;
                    var textNode = null;
                    if (CourseCategoryData[i].type == 1) {
                        challengeA = newElement("a", {
                            target: "_blank",
                            href: "http://wenwen.soso.com/z/" + CourseCategoryData[i].cid
                        });
                        challengeA.innerHTML = "\u5b66\u4e60\u77e5\u8bc6"
                    }
                    else {
                        if (CourseCategoryData[i].type == 2) {
                            challengeA = newElement("a", {
                                target: "_blank",
                                href: CourseCategoryData[i].cid
                            });
                            challengeA.innerHTML = "\u4e86\u89e3\u95ee\u95ee"
                        }
                        else {
                            if (CourseCategoryData[i].type == 3) {
                                challengeA = newElement("a", {
                                    target: "_blank",
                                    href: CourseCategoryData[i].cid
                                });
                                challengeA.innerHTML = "\u5b66\u4e60\u77e5\u8bc6"
                            }
                        }
                    }
                    li.appendChild(span1);
                    li.appendChild(span2);
                    if (CourseCategoryData[i].type != 0 && challengeA != null) {
                        li.appendChild(challengeA)
                    }
                    if (CourseCategoryData[i].isHot) {
                        var hotSpan = newElement("span", {
                            "class": "hot_icon"
                        });
                        hotSpan.innerHTML = "Hot!";
                        li.appendChild(hotSpan);
                        li.className = "highlight"
                    }
                    ul.appendChild(li)
                }
            }
        }
    }
    function initTodayTopList(uid, key, num){
        if (num && num > 0) {
            topListSize = num
        }
        if (uid) {
            userId = uid
        }
        if (key) {
            keyParam = key
        }
        ajax_time_opr[OPR_GET_TOP20_LIST] = new Date().getTime();
        _getData(_displayTodayTopList, OPR_GET_TOP20_LIST, null);
        if (challengeType == 1) {
            var tophref = get("toptitlehref");
            if (tophref) {
                tophref.innerHTML = "\u6311\u6218\u72b6\u5143\u699c";
                tophref.href = "QzoneCourseHome.htm";
                tophref.target = "_self"
            }
        }
    }
    function initTopList(uid, key){
        if (uid) {
            userId = uid
        }
        if (key) {
            keyParam = key
        }
        _getData(_displayTopList, OPR_GET_TOP_LIST, null)
    }
    function _displayTopList(data){
        topListSize = 10;
        if (data.result == 1) {
            var ol = get("allTopList");
            if (ol == null) {
                return
            }
            ol.innerHTML = "";
            uins = uins || new Array();
            for (var i = 0; i < data.data.length; i++) {
                var d = data.data[i];
                var li = newElement("li");
                var span1 = newElement("span", {
                    "class": "order"
                });
                span1.innerHTML = i + 1;
                var img = newElement("img", {
                    src: "http://imgcache.qq.com/qzone_v4/client/userinfo_icon/5001.gif",
                    id: "img_" + d.uin
                });
                var a = newElement("a", {
                    "class": "user_name",
                    href: "javascript:;",
                    id: "name_" + d.uin
                });
                a.innerHTML = d.uin;
                var span2 = newElement("span");
                span2.innerHTML = d.points;
                li.appendChild(span1);
                li.appendChild(img);
                li.appendChild(a);
                li.appendChild(span2);
                ol.appendChild(li);
                uins.push(d.uin)
            }
        }
    }
    function getUserScoreName(s){
        var datas = ["\u7ae5\u751f", "\u9ad8\u7ea7\u4e66\u7ae5", "\u79c0\u624d", "\u4e3e\u4eba", "\u89e3\u5143", "\u8d21\u58eb", "\u4f1a\u5143", "\u8fdb\u58eb", "\u63a2\u82b1", "\u699c\u773c", "\u72b6\u5143", "\u7ff0\u6797\u5927\u5b66\u58eb"];
        var scores = [0, 300, 600, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 6000, 8000];
        var name = "\u7ae5\u751f";
        for (var i = 0; i < scores.length - 1; i++) {
            if (s > scores[i] && s <= scores[i + 1]) {
                name = datas[i];
                break
            }
        }
        return name
    }
    function initUserInfo(userData){
        var datas = ["\u7ae5\u751f", "\u9ad8\u7ea7\u4e66\u7ae5", "\u79c0\u624d", "\u4e3e\u4eba", "\u89e3\u5143", "\u8d21\u58eb", "\u4f1a\u5143", "\u8fdb\u58eb", "\u63a2\u82b1", "\u699c\u773c", "\u72b6\u5143", "\u7ff0\u6797\u5927\u5b66\u58eb"];
        var scores = [0, 300, 600, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 6000, 8000];
        get("todayPoint").innerHTML = todayScore;
        var all = 300, text1 = "\u7ae5\u751f", text2 = "\u9ad8\u7ea7\u4e66\u7ae5";
        for (var i = 0; i < scores.length; i++) {
            if (maxScoure > scores[i] && maxScoure <= scores[i + 1]) {
                all = scores[i + 1];
                text1 = datas[i];
                text2 = datas[i + 1];
                break
            }
        }
        if (maxScoure > 8000) {
            all = 8000, text1 = "\u7ff0\u6797\u5927\u5b66\u58eb", text2 = "-"
        }
        get("l_title").innerHTML = "<strong>" + text1 + "</strong>";
        get("r_title").innerHTML = text2;
        get("maxPoint").innerHTML = "<strong>" + maxScoure + "</strong>/" + all;
        try {
            get("maxLength").style.width = (maxScoure * 100 / all) + "%"
        } 
        catch (e) {
        }
        initSignInfo(userData);
        uins.push(userId);
        if (QZONE && QZONE.FP && QZONE.FP.getPortraitList) {
            QZONE.FP.getPortraitList(uins, function(data){
                if (data != null) {
                    for (var i = 0; i < uins.length; i++) {
                        if (data[uins[i]]) {
                            var nn = data[uins[i]][6];
                            if (get("img_" + uins[i])) {
                                get("img_" + uins[i]).src = data[uins[i]][0]
                            }
                            if (nn.trim() != "") {
                                if (get("name_" + uins[i])) {
                                    get("name_" + uins[i]).innerHTML = nn
                                }
                            }
                        }
                    }
                }
            })
        }
    }
    function initSignInfo(userData){
        var totalSignNum = get("totalSignNum");
        var signLink = get("signLink");
        var conSignNum = get("conSignNum");
        var conSignTitle = get("conSignTitle");
        signLink.onclick = function(){
        };
        if (userData.issign == 0) {
            signLink.className = "btn_checkin";
            signLink.onclick = function(){
                _getData(_signResult, OPR_DAY_SIGN, null)
            };
            conSignTitle.title = "\u4eca\u65e5\u7b7e\u5230\u53ef\u83b7\u5f97" + (userData.consignnum + 1) + "\u5b66\u5206"
        }
        else {
            if (userData.issign == 1) {
                signLink.className = "btn_hascheckin";
                conSignTitle.title = "\u4eca\u65e5\u7b7e\u5230\u5df2\u83b7\u5f97" + (userData.consignnum) + "\u5b66\u5206"
            }
        }
        totalSignNum.innerHTML = userData.totalsignnum;
        conSignNum.innerHTML = userData.consignnum
    }
    function _signResult(data){
        if (data && data.result && data.result == 1) {
            _getData(_displayTodayTopList, OPR_GET_TOP20_LIST, null)
        }
    }
    function initCourse(cateId, param, type, uid){
        keyParam = param;
        challengeType = type;
        vcourseCategoryId = cateId;
        userId = uid;
        var background = _getCateBackById(cateId);
        if (type == 0) {
            background = DEFAULT_BACK_URL
        }
        else {
            get("coursehtitle").addClassName("title_test")
        }
        if (background != "") {
            get("contentWrap")["style"]["background"] = 'url("http://cache.soso.com/wenwen/' + background + '") no-repeat scroll 0 0 transparent'
        }
        if (vcourseCategoryId == 10) {
            $("coursehtitle").className = "titie_arena btn_qzone_task"
        }
        TOKEN = _getToken();
        ajax_time_opr[OPR_START_CHALLENGE] = new Date().getTime();
        _getData(_startCourse, OPR_START_CHALLENGE, {
            groupid: vcourseCategoryId < 0 ? 0 : vcourseCategoryId,
            istest: challengeType,
            token: TOKEN
        })
    }
    function challenge(catid, chType){
        document.location = "QzoneCourse.e?sp=" + catid + "&sp=" + chType
    }
    function reChallenge(){
        __sosostat.run();
        _t = 0;
        initCourse(vcourseCategoryId, keyParam, challengeType, userId)
    }
    function findAnswerInWenwen(){
        _sendStat("help", "");
        var url = "";
        var qid = $("qId").value;
        if (QidToWenwenQuestion[qid]) {
            url = "http://wenwen.soso.com/z/q" + QidToWenwenQuestion[qid] + ".htm?cid=w.search.qzcourse"
        }
        var title = $("quesTitle");
        if (title && url == "") {
            url = "http://wenwen.soso.com/z/Search.e?sp=S" + encodeURIComponent(title.innerHTML.replace("\u9898\u76ee：", "")) + "&cid=w.search.qzcourse"
        }
        if (url != "") {
            if (Zhishi.Browser.isIE) {
                var a = document.createElement("a");
                a.href = url;
                a.target = "_blank";
                document.body.appendChild(a);
                a.click()
            }
            else {
                window.open(url)
            }
        }
    }
    function _startCourse(data2){
        ajax_time_opr[OPR_START_CHALLENGE] = new Date().getTime() - ajax_time_opr[OPR_START_CHALLENGE];
        _sendStat("sp", OPR_START_CHALLENGE + "|" + ajax_time_opr[OPR_START_CHALLENGE]);
        if (data2 && data2.result && data2.result == 1) {
            var resetTime = TIME_LIMIT_TEST;
            if (challengeType == 0) {
                resetTime = TIME_LIMIT_CHALLENGE
            }
            $("restTime").innerHTML = resetTime;
            if (timer == null) {
                timer = setInterval(_timerOpr, 1000)
            }
            _displayCourse(data2)
        }
    }
    function _displayCourse(data2){
        if (timer == null) {
            return
        }
        get("contentWrap").show();
        if (get("priseContent")) {
            get("priseContent").hide()
        }
        if (get("prisePic")) {
            get("prisePic").src = "http://cache.soso.com/wenwen/i/diploma.jpg"
        }
        get("errorTips").hide();
        get("reTestCon").hide();
        get("reTest").hide();
        if (data2.result == 1) {
            buttonLock = false;
            var record = null;
            get("chengji_notest").hide();
            get("chengji_test").hide();
            if (challengeType == 0) {
                get("chengji_notest").show();
                record = gets("#chengji_notest em");
                currentpoints_notest = data2.data.temprecord
            }
            else {
                get("chengji_test").show();
                record = gets("#chengji_test em");
                currentpoints_test = data2.data.temprecord
            }
            if (record != null) {
                record[0].innerHTML = data2.data.temprecord;
                record[1].innerHTML = data2.data.record
            }
            var title = get("quesTitle");
            title.show();
            title.innerHTML = "\u9898\u76ee：" + data2.data.qtitle;
            $("qId").value = data2.data.qid;
            var qAnswers = $("qAnswers");
            qAnswers.innerHTML = "";
            get("qAnswers").show();
            for (var i = 0; i < data2.data.answers.length; i++) {
                var qa = data2.data.answers[i];
                var li = newElement("li");
                var span = newElement("span");
                span.innerHTML = (i + 1) + "、" + qa.atitle;
                var a = newElement("a", {
                    href: "javascript:QzApp.answerQ(" + data2.data.qid + "," + qa.aid + ");;",
                    "class": "btn_select"
                });
                li.appendChild(span);
                li.appendChild(a);
                qAnswers.appendChild(li)
            }
			wgu();
        }
    }
    function answerQuestion(qid, aid){
        __sosostat.run();
        if (!buttonLock) {
            buttonLock = true;
            ajax_time_opr[OPR_ANSWER_QUESTION] = new Date().getTime();
            _getData(_answerEnd, OPR_ANSWER_QUESTION, {
                groupid: vcourseCategoryId,
                istest: challengeType,
                qid: qid,
                aid: aid,
                token: TOKEN
            })
        }
    }
    function _displayTodayTopList(data){
        if (data.userData.score != null) {
            maxScoure = data.userData.score
        }
        if (data.userData.dayrecord != null) {
            todayScore = data.userData.dayrecord
        }
        _displayList(data, "todayTopList");
        initUserInfo(data.userData)
    }
    function _displayList(data, olid){
        if (data.result == 1) {
            var ol = get(olid);
            if (ol == null) {
                return
            }
            ol.innerHTML = "";
            uins = uins || new Array();
            for (var i = 0; i < data.data.length && i < topListSize; i++) {
                var d = data.data[i];
                var li = newElement("li");
                var span1 = newElement("span", {
                    "class": "order"
                });
                span1.innerHTML = i + 1;
                var img = newElement("img", {
                    src: "http://imgcache.qq.com/qzone_v4/client/userinfo_icon/5001.gif",
                    id: "img_" + d.uin
                });
                var a = newElement("a", {
                    "class": "user_name",
                    href: "javascript:;",
                    id: "name_" + d.uin
                });
                a.innerHTML = d.uin;
                var span2 = newElement("span");
                span2.innerHTML = d.points;
                li.appendChild(span1);
                li.appendChild(img);
                li.appendChild(a);
                li.appendChild(span2);
                ol.appendChild(li);
                uins.push(d.uin)
            }
        }
    }
    function _answerEnd(data){
        ajax_time_opr[OPR_ANSWER_QUESTION] = new Date().getTime() - ajax_time_opr[OPR_ANSWER_QUESTION];
        _sendStat("sp", OPR_ANSWER_QUESTION + "|" + ajax_time_opr[OPR_ANSWER_QUESTION] + "|an|" + data.result + "|cat|" + vcourseCategoryId + "|ty|" + challengeType);
        if (data.result == 1) {
            _answerRight(data)
        }
        else {
            if (data.result == -1) {
                _stopTimer();
                _answerError(data)
            }
            else {
                if (data.result == -2) {
                    _stopTimer();
                    _timeEnd(false, data)
                }
            }
        }
    }
    function _timerOpr(){
        time += 1;
        if (challengeType == 0) {
            if (time >= TIME_LIMIT_CHALLENGE) {
                _stopTimer();
                _timeEnd(true)
            }
            else {
                get("restTime").innerHTML = TIME_LIMIT_CHALLENGE - time
            }
        }
        else {
            if (challengeType == 1) {
                if (time >= TIME_LIMIT_TEST) {
                    _stopTimer();
                    _timeEnd(true)
                }
                else {
                    get("restTime").innerHTML = TIME_LIMIT_TEST - time
                }
            }
        }
    }
    function _stopTimer(){
        clearInterval(timer);
        timer = null;
        time = 0
    }
    function _timeEnd(isClient){
        if (isClient) {
            _getData(_endOpr, OPR_END_CHALLENGE, {
                token: TOKEN,
                istest: challengeType,
                groupid: vcourseCategoryId
            })
        }
        get("restTime").innerHTML = 0;
        get("quesTitle").hide();
        get("qAnswers").hide();
        get("tipsSpan").hide();
        var error = get("errorTips");
        if (challengeType == 0) {
            if (currentpoints_notest > 10 && Math.random() > 0.4) {
                get("contentWrap").hide();
                get("priseContent").show();
                generatePrisePic(currentpoints_notest)
            }
            else {
                error.innerHTML = "TimeOver！\u54e5\u7f3a\u7684\u4ec5\u4ec5\u662f\u65f6\u95f4！";
                error.show();
                get("reTestCon").show()
            }
        }
        else {
            error.show();
            _testEndOpr(currentpoints_test, error, true)
        }
    }
    function _endOpr(data){
        if (data.result == 1) {
            var record = null;
            get("chengji_notest").hide();
            get("chengji_test").hide();
            if (challengeType == 0) {
                get("chengji_notest").show();
                record = gets("#chengji_notest em")
            }
            else {
                get("chengji_test").show();
                record = gets("#chengji_test em")
            }
            if (record != null) {
                record[0].innerHTML = data.data.temprecord;
                record[1].innerHTML = data.data.record
            }
        }
    }
    function _answerError(data){
        get("quesTitle").hide();
        get("qAnswers").hide();
        get("tipsSpan").hide();
        var error = get("errorTips");
        error.show();
        var test_find = '<br/><a class="back_index" style="float: none;" onclick="QzApp.findAnswerInWenwen();" href="javascript:;">\u53bb\u95ee\u95ee\u627e\u7b54\u6848&gt;&gt;</a>';
        if (challengeType == 0) {
            var content = "";
            if (currentpoints_notest > 10) {
                content = "\u5389\u5bb3\u554a！\u4f60\u51b2\u7834\u4e8610\u9053\u9898\u5173\u5361，\u5f97\u5230" + currentpoints_notest + "\u5206！<br/>\u8fd9\u5c31\u662f\u6781\u9650\u4e86\u5417？\u7ee7\u7eed\u6311\u6218\u81ea\u5df1\u5427！";
                get("reTest").show()
            }
            else {
                if (currentpoints_notest == 10) {
                    content = "\u4e0d\u662f\u5427？！\u53ea\u5dee\u4e00\u70b9\u70b9，\u518d\u5bf91\u9053\u5c31\u5f97\u5206\u5566！\u66ff\u4f60\u4e0d\u7518\u5fc3\u554a…<br/>\u6709\u6f5c\u529b\u5c31\u518d\u6765\u4e00\u6b21\u5457！";
                    get("reTest").show()
                }
                else {
                    content = "\u676f\u5177\u554a！\u6ca1\u7b54\u6ee110\u9053\u9898，\u6211\u4eec\u5f88\u4e0d\u5fcd\u5fc3\u7684\u6263\u9664\u4f605\u5b66\u5206…<br/>\u5148\u53bb\u968f\u5802\u6d4b\u8bd5\u4e00\u4e0b\u5427~";
                    get("reTest").show()
                }
            }
            error.innerHTML = content + test_find
        }
        else {
            _testEndOpr(data.data.temprecord, error, false)
        }
    }
    function _testEndOpr(temprecord, error, isTimeEnd){
        var re = get("reChallenge2");
        var reselect = get("reSelect");
        var prefixText = "Time over！";
        var test_find = '<br/><a class="back_index" style="float: none;" onclick="QzApp.findAnswerInWenwen();" href="javascript:;">\u53bb\u95ee\u95ee\u627e\u7b54\u6848&gt;&gt;</a>';
        if (vcourseCategoryId == 10) {
            if (temprecord >= 5) {
                error.innerHTML = "\u606d\u559c！\u8fd9\u4e2a\u6d4b\u8bd5\u5bf9\u60a8\u6765\u8bf4\u592a\u5c0f\u83dc\u4e00\u789f\u4e86~~";
                re.className = "btn_enterschool";
                re.href = "QzoneCourseHome.htm";
                re.setAttribute("onclick", "function(){}")
            }
            else {
                if (!isTimeEnd) {
                    error.innerHTML = "\u7b54\u9519\u4e86！\u4f60\u79bb\u8fbe\u4eba\u4ec5\u4e00\u6b65\u4e4b\u9065... " + test_find
                }
                else {
                    error.innerHTML = "Time Over！\u54e5\u7f3a\u7684\u4ec5\u4ec5\u662f\u65f6\u95f4~~"
                }
                re.className = "btn_again"
            }
        }
        else {
            if (!isTimeEnd) {
                prefixText = "\u7b54\u9519\u4e86！"
            }
            if (temprecord < 10) {
                error.innerHTML = prefixText + "\u5b7a\u5b50\u53ef\u6559\u4e5f，\u6f5c\u529b\u65e0\u7a77！ " + test_find;
                re.className = "btn_again btn_zaijiezaili";
                reselect.className = "btn_reselect"
            }
            else {
                error.innerHTML = prefixText + "\u6b64\u4e43\u53ef\u9020\u4e4b\u624d，\u65e5\u540e\u5fc5\u6210\u5927\u5668！" + test_find;
                re.className = "btn_again btn_zaijiezaili";
                reselect.className = "btn_reselect"
            }
        }
        get("reTestCon").show()
    }
    function _answerRight(data){
        var tipsSpan = get("tipsSpan");
        tipsSpan.className = "correct_ico";
        tipsSpan.fadeIn(0.2);
        setTimeout(function(){
            get("tipsSpan").className = "";
            _displayCourse(data)
        }, 800)
    }
    function _getCateBackById(id){
        if (CourseCategoryData) {
            for (var i = 0; i < CourseCategoryData.length; i++) {
                if (CourseCategoryData[i].id == id) {
                    return CourseCategoryData[i].bgPic;
                    break
                }
            }
        }
        return ""
    }
    function _getData(callback, type, param){
        if (userId != "") {
            var url = "http://wenwen.qq.com/QzoneAPI/school" + API_URL[userId % API_URL.length];
            var p = new Array();
            p.push("userid=");
            p.push(userId);
            p.push("&param=");
            p.push(keyParam);
            p.push("&type=");
            p.push(type);
            if (param != null) {
                for (var o in param) {
                    p.push("&");
                    p.push(o);
                    p.push("=");
                    p.push(param[o])
                }
            }
            url += p.join("");
            Zhishi.Ajax.sendRequest("GET", url, {
                onSuccess: function(d){
                    if (d != null && d != "") {
                        d = d.replace(/\r\n/gi, "");
                        var index = d.indexOf("{");
                        if (index > 0) {
                            d = d.substr(index, d.length - index)
                        }
                    }
                    var data = null;
                    try {
                        data = eval("(" + d + ")")
                    } 
                    catch (e) {
                        _systemError(type);
                        _sendStat("error", "ajaxEvalError|" + type + "|d|" + d)
                    }
                    if (data != null && data.result == 0) {
                        _systemError(type);
                        _sendStat("error", "ajaxDataError|" + type)
                    }
                    else {
                        try {
                            if (callback) {
                                callback(data)
                            }
                        } 
                        catch (e) {
                            _sendStat("error", "codeError|" + type + "|e|" + e)
                        }
                    }
                },
                onErr: function(){
                    _sendStat("error", "ajaxError|" + type);
                    if (type == OPR_ANSWER_QUESTION) {
                        var currentpoints = $("todayCurrentPoint").innerHTML.replace("\u5206", "").replace("\u5173", "");
                        var data2 = {
                            result: -1,
                            pointintop20: 0,
                            data: {
                                maxpoints: 3,
                                currentpoints: currentpoints
                            }
                        };
                        callback(data2)
                    }
                    else {
                        _systemError(type)
                    }
                },
                timeOut: 8000
            })
        }
    }
    function _getToken(){
        var d = new Date();
        return d.getTime()
    }
    function _sendStat(type, value){
        new Image().src = "http://wenwen.soso.com/count.gif?ver=2&val=ac|u|" + userId + "|t|" + type + "|v|" + value
    }
    function _systemError(type){
        var vaue = userId + "," + type;
        if (type != OPR_GET_TOP20_LIST) {
            if (document.location.href.indexOf("QzoneCourseHome") == -1) {
                alert("\u5bf9\u4e0d\u8d77！\u6b64\u65f6\u95ee\u95ee\u5b66\u5802\u4eba\u6ee1\u4e3a\u60a3，\u8bf7\u7a0d\u540e\u518d\u6765~~~");
                document.location = "QzoneCourseHome.htm"
            }
        }
    }
    function initState(){
        _sendStat("pv", document.location.href)
    }
    function sendQzoneBlog(){
        if (prisePicPath == "") {
            QZONE.FP.showMsgbox("\u5df2\u8f6c\u8f7d！", 1, 2000, pageY + 320 - QZONE.FP.getScrollTop());
            return
        }
        var url = PRISE_BLOG_URL + "?p=" + encodeURIComponent(prisePicPath);
        Zhishi.Ajax.sendRequest("GET", url, {
            onSuccess: function(d){
                var data = eval("(" + d + ")");
                if (data.code == 0) {
                    _sendStat("blogsuc", "");
                    QZONE.FP.showMsgbox("\u8f6c\u8f7d\u6210\u529f！", 1, 2000, pageY + 320 - QZONE.FP.getScrollTop());
                    prisePicPath = ""
                }
                else {
                    QZONE.FP.showMsgbox("\u7cfb\u7edf\u5f02\u5e38，\u8bf7\u7a0d\u540e\u91cd\u8bd5！", 1, 2000, pageY + 320 - QZONE.FP.getScrollTop());
                    _sendStat("blogerror", "msg|" + d.msg + "|p|" + prisePicPath)
                }
            },
            onErr: function(){
            },
            timeOut: 8000
        })
    }
    function generatePrisePic(socre){
        var r = QZONE.FP.getPortraitList([userId], function(data){
            userName = data[userId][6];
            var url = PRISE_PIC_URL + "?s=" + socre + "&u=" + encodeURIComponent(userName);
            Zhishi.Ajax.sendRequest("GET", url, {
                onSuccess: function(d){
                    var data = eval("(" + d + ")");
                    if (data.result == 0) {
                        _sendStat("priseerror", "1");
                        QZONE.FP.showMsgbox("\u7cfb\u7edf\u5f02\u5e38，\u8bf7\u7a0d\u540e\u91cd\u8bd5！", 1, 2000, pageY + 320 - QZONE.FP.getScrollTop())
                    }
                    else {
                        _sendStat("prisesuc", socre);
                        prisePicPath = "http://pic.wenwen.soso.com/p/" + data.path;
                        _t = new Date().getTime();
                        var img = get("prisePic");
                        img.src = prisePicPath;
                        img.onload = function(){
                            if (_t > 0 && get("priseContent").visible()) {
                                _sendStat("prisepicload", new Date().getTime() - _t)
                            }
                        };
                        img.onerror = function(){
                            _t = 0
                        }
                    }
                },
                onErr: function(){
                    _sendStat("priseerror", "2")
                },
                timeOut: 8000
            })
        });
        if (!r) {
            QZONE.FP.showMsgbox("\u83b7\u53d6\u5462\u79f0\u65f6\u51fa\u9519，\u8bf7\u7a0d\u540e\u91cd\u8bd5！", 1, 2000, pageY + 320 - QZONE.FP.getScrollTop())
        }
    }
    return {
        challenge: challenge,
        reChallenge: reChallenge,
        initCourseCategory: initCourseCategory,
        initTodayTopList: initTodayTopList,
        findAnswerInWenwen: findAnswerInWenwen,
        initCourse: initCourse,
        answerQ: answerQuestion,
        initState: initState,
        sendQzoneBlog: sendQzoneBlog,
        initTopList: initTopList
    }
})();
